freeslot(
	"S_PLAY_AMYFLIP1",
	"S_PLAY_AMYFLIP2",
	"S_PLAY_AMYFLIP3",
	"S_PLAY_AMYFLIP4",
	"S_PLAY_AMYFLIP5",
	"S_PLAY_AMYFLIP6",
	"S_PLAY_AMYFLIP7",
	"S_PLAY_HELIHAMMER1",
	"S_PLAY_HELIHAMMER2",
	"S_PLAY_HELIHAMMER3",
	"S_PLAY_HELIHAMMER4",
	"S_PLAY_HELIHAMMER5",
	"S_PLAY_HELIHAMMER6",
	"S_PLAY_HELIHAMMER7",
	"S_PLAY_HELIHAMMER8"
)

states[S_PLAY_AMYFLIP1] = {SPR_PLAY, SPR2_TWIN, 1, nil, 0, 0, S_PLAY_AMYFLIP2}
states[S_PLAY_AMYFLIP2] = {SPR_PLAY, SPR2_TWIN, 1, nil, 0, 0, S_PLAY_AMYFLIP3}
states[S_PLAY_AMYFLIP3] = {SPR_PLAY, SPR2_TWIN, 1, nil, 0, 0, S_PLAY_AMYFLIP4}
states[S_PLAY_AMYFLIP4] = {SPR_PLAY, SPR2_TWIN, 1, nil, 0, 0, S_PLAY_AMYFLIP5}
states[S_PLAY_AMYFLIP5] = {SPR_PLAY, SPR2_TWIN, 1, nil, 0, 0, S_PLAY_AMYFLIP6}
states[S_PLAY_AMYFLIP6] = {SPR_PLAY, SPR2_TWIN, 1, nil, 0, 0, S_PLAY_AMYFLIP7}
states[S_PLAY_AMYFLIP7] = {SPR_PLAY, SPR2_TWIN, 1, nil, 0, 0, S_PLAY_FALL}

states[S_PLAY_HELIHAMMER1] = {SPR_PLAY, SPR2_MLEL, 1, A_PlaySound, sfx_putput, 1, S_PLAY_HELIHAMMER2}
states[S_PLAY_HELIHAMMER2] = {SPR_PLAY, SPR2_MLEL, 1, nil, 0, 0, S_PLAY_HELIHAMMER3}
states[S_PLAY_HELIHAMMER3] = {SPR_PLAY, SPR2_MLEL, 1, nil, 0, 0, S_PLAY_HELIHAMMER4}
states[S_PLAY_HELIHAMMER4] = {SPR_PLAY, SPR2_MLEL, 1, nil, 0, 0, S_PLAY_HELIHAMMER5}
states[S_PLAY_HELIHAMMER5] = {SPR_PLAY, SPR2_MLEL, 1, A_PlaySound, sfx_putput, 1, S_PLAY_HELIHAMMER6}
states[S_PLAY_HELIHAMMER6] = {SPR_PLAY, SPR2_MLEL, 1, nil, 0, 0, S_PLAY_HELIHAMMER7}
states[S_PLAY_HELIHAMMER7] = {SPR_PLAY, SPR2_MLEL, 1, nil, 0, 0, S_PLAY_HELIHAMMER8}
states[S_PLAY_HELIHAMMER8] = {SPR_PLAY, SPR2_MLEL, 1, nil, 0, 0, S_PLAY_HELIHAMMER1}

addHook("AbilitySpecial", function(player) //Heli-Hammer
    if player.mo and player.mo.skin == "amy"
	and player.pflags & PF_JUMPED
	and not (player.pflags & PF_THOKKED)
	and not (player.pflags & PF_SHIELDABILITY)
		player.mo.state = S_PLAY_HELIHAMMER1
		player.mo.helihammer = 1
		player.pflags = $1|PF_THOKKED
		return true
    end 
end)

addHook("MobjThinker", function(mobj)
	local player = mobj.player
	if (player.mo and player.mo.skin == "amy")
		
			if (player.speed > 31*FRACUNIT)
			and not (player.panim == PA_ABILITY2)
				player.charability2 = CA2_NONE
			elseif (player.speed < 31*FRACUNIT)
			and not (player.panim == PA_ABILITY2)
				player.charability2 = CA2_MELEE
			end
			
			if not P_IsObjectOnGround(player.mo)
			    player.charability2 = CA2_MELEE
			end
			
	end
end, MT_PLAYER)

addHook("MobjThinker", function(mobj)
	local player = mobj.player
	if (player.mo and player.mo.skin == "amy")
	
	    if (player.mo.falltimer == nil)
			player.mo.falltimer = 0
		end
		
		if (player.mo.falltimer > 0)
			player.mo.falltimer = $ - 1
		end
		
		if (player.mo.helitimer == nil)
		    player.mo.helitimer = 0
		end
	
	    if (player.mo.amytimer == nil)
			player.mo.amytimer = 0
		end
		
		if (player.mo.state >= S_PLAY_HELIHAMMER1) and (player.mo.state <= S_PLAY_HELIHAMMER8)
		    player.charability = CA_GLIDEANDCLIMB
		else
		    player.charability = CA_TWINSPIN
		end
		
		if (player.mo.state >= S_PLAY_HELIHAMMER1) and (player.mo.state <= S_PLAY_HELIHAMMER8)
			player.mo.amytimer = $1 + 1
		end
			
		if (player.mo.state >= S_PLAY_HELIHAMMER1) and (player.mo.state <= S_PLAY_HELIHAMMER8)
		and (player.mo.amytimer > 2*TICRATE)
		    player.mo.state = S_PLAY_FALL
			player.pflags = $1|PF_THOKKED
		end
			
		if (player.mo.state >= S_PLAY_HELIHAMMER1) and (player.mo.state <= S_PLAY_HELIHAMMER8)
		    player.mo.helihammer = 1
		end
			
		if (player.mo.state == S_PLAY_HELIHAMMER1) and not (player.mo.eflags & MFE_UNDERWATER) or (player.mo.state == S_PLAY_HELIHAMMER4) and not (player.mo.eflags & MFE_UNDERWATER) or (player.mo.state == S_PLAY_HELIHAMMER8) and not (player.mo.eflags & MFE_UNDERWATER)
		    A_ZThrust(player.mo, 1, 0)
		end
			
		if (player.mo.state == S_PLAY_HELIHAMMER1)
		and (player.mo.eflags & MFE_UNDERWATER)
			A_ZThrust(player.mo, 1, 0)
		end
			
		if (player.mo.state == S_PLAY_FALL)
		and (player.mo.helihammer == 1)
		or P_IsObjectOnGround(player.mo)
		and (player.mo.helihammer == 1)
		    player.mo.helihammer = 0
		end
			
		if P_IsObjectOnGround(player.mo)
		and (player.mo.amytimer)
		    player.mo.amytimer = 0
		end

		if not (player.cmd.buttons & BT_JUMP)
		and (player.mo.state >= S_PLAY_HELIHAMMER1)
		and (player.mo.state <= S_PLAY_HELIHAMMER8)
		    player.mo.state = S_PLAY_FALL
			player.pflags = $1|PF_THOKKED
		end
		
		if (player.mo.helihammer == 1)
		    player.pflags = $1 & ~PF_NOJUMPDAMAGE
		else
		    player.pflags = $1|PF_NOJUMPDAMAGE
		end
		
		if player.ctfteam == 0
		    player.ctfname = player.name
	    elseif player.ctfteam == 1
		    player.ctfname = "\x85"..player.name.."\x80"
	    elseif player.ctfteam == 2
	     	player.ctfname = "\x84"..player.name.."\x80"
		end
		
		if player.mo.helihammer == 1
			local sectorthing = P_PlayerTouchingSectorSpecial(player, 0, 0)
			if sectorthing.valid then
				for fof in sectorthing.ffloors()
					if fof.valid and (fof.flags & FF_BUSTUP) and (fof.flags & FF_EXISTS)
					and not (tracer and tracer.type == MT_TUBEWAYPOINT)
					and not player.powers[pw_carry]
					and (abs(fof.topheight - player.mo.z) <= 30*player.mo.scale) then
						EV_CrumbleChain(player.sectorthing, fof)
					end
				end
			end
		end
	
		if (player.mo.falltimer == 0)
		and (player.mo.state == S_PLAY_MELEE_FINISH)
		and not P_IsObjectOnGround(player.mo)
		and not P_PlayerInPain(player)
		and not P_CheckDeathPitCollide(player.mo)
		and not (player.panim == PA_ABILITY)
		and not (player.panim == PA_MELEE_LANDING)
		and not (player.mo.state == S_PLAY_DEAD)
		and not (player.mo.state == S_PLAY_PAIN)
		and not (player.mo.state == S_PLAY_RIDE)
		and not (player.mo.state == S_PLAY_GASP)
		and not (player.mo.state == S_PLAY_MELEE_LANDING)
		and not (player.mo.state == S_PLAY_FALL)
		and not (player.mo.state == S_PLAY_MELEE_LANDING)
		and not (player.pflags & PF_THOKKED)
		and not (player.powers[pw_carry])
		and not (player.playerstate == PST_DEAD)
			player.mo.state = S_PLAY_FALL
			player.pflags = $1|PF_JUMPED
			player.pflags = $1|PF_NOJUMPDAMAGE
		end
		
		if not (player.mo.hammerjump)
			player.mo.hammerjump = 0
		end
		
		if player.mo.hammerjump == 0
			player.jumpfactor = skins[player.mo.skin].jumpfactor
		end
		
		if (FixedDiv(player.speed, player.mo.scale) > 15*FRACUNIT)
		and P_IsObjectOnGround(player.mo)
		and not P_InQuicksand(player.mo)
		and not P_PlayerInPain(player)
		and not P_CheckDeathPitCollide(player.mo)
		and not (player.pflags & PF_SLIDING)	
		and not (player.pflags & PF_SPINNING)
		and not (player.pflags & PF_JUMPED)
		and not (player.powers[pw_carry])
		and not (player.skidtime > 0)
		and not (player.exiting)
		and not (player.gotflag)
		and not (player.mo.hammerjump == 1)
		and not (player.panim == PA_ABILITY)
		and not (player.panim == PA_ABILITY2)
		and not (player.panim == PA_MELEE_LANDING)
		//and (player.cmd.forwardmove > 0)
			if (player.cmd.buttons & BT_USE)
				player.mo.hammerjump = 1
			end
		end
	
		if (player.mo.hammerjump == 1)
		and not (player.pflags & PF_JUMPED)
			player.jumpfactor = 0
			player.mo.state = S_PLAY_AMYFLIP1
			if (player.mo.state == S_PLAY_AMYFLIP1)
				player.mo.hammerjump = 0
				if (FixedDiv(player.speed, player.mo.scale) > 15*FRACUNIT and FixedDiv(player.speed, player.mo.scale) < 31*FRACUNIT)
					A_ZThrust(player.mo, 15, 0)
				elseif (FixedDiv(player.speed, player.mo.scale) > 30*FRACUNIT)
					A_ZThrust(player.mo, 20, 0)
				else
					A_ZThrust(player.mo, 0, 0)
				end
				//A_Thrust(player.mo, 15, 1)
				S_StartSound(player.mo, sfx_s3k8b)
			end
			player.mo.falltimer = TICRATE-5
			return true
		end
			
	end
end, MT_PLAYER)

addHook("ThinkFrame", do //Credit to DerpyBubblez for this code
	for player in players.iterate
		if(player.mo.skin == "amy")
			if (player.mo.helihammer == 1)
			
				player.mo.helitimer = $1 + 1
				
				if (player.mo.helitimer > 7)
					player.mo.helitimer = 0
				end
				
				player.drawangle = player.mo.helitimer * ANGLE_45
			end
		end
	end
end)

addHook("MobjCollide", function(spike, amy)
	if not (amy.player and amy.skin == "amy")
		return nil
	end
	if (amy.z > spike.z+spike.height+10*FRACUNIT)
	or (spike.z > amy.z+amy.height)
		return nil 
	elseif (amy.player.mo.helihammer == 1)
		spike.health = 0
		S_StartSound(amy, spike.info.deathsound)
		P_KillMobj(spike, amy, amy)
		return false
	end
end, MT_SPIKE)

addHook("MobjMoveCollide", function(amy, spring)
	if not (amy.player and amy.skin == "amy") or not (spring.flags & MF_SPRING)
		return nil
	elseif (amy.player.mo.helihammer == 1) and (amy.player.powers[pw_justsprung])
		S_StartSound(amy, sfx_sprong)
		amy.state = S_PLAY_SPRING
		amy.player.mo.helihammer = 0
		amy.player.mo.momz = $ * 120/100
		amy.player.powers[pw_justsprung] = 0
		return false
	end
end, MT_PLAYER)